﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


/// <summary>
/// 键盘处理类
/// Keyevent.Instance().GetWindows(this.Handle,"Progman");
/// </summary>


class Keyevent
{
    public static Keyevent keyevent;
    private MessageBase MessageBase;
    private Keyevent()
    {
        MessageBase = new MessageBase();
    }

    //实例化
    public static Keyevent Instance()
    {
        if (keyevent == null)
        {
            return new Keyevent();
        }
        return keyevent;
    }

    //获取目标窗口
    public void GetWindows(IntPtr hWndChild, string windowsName)
    {
      //  IntPtr handle = MessageBase.FindWindow("Progman", "Program Manager");
        //MessageBase.SetForegroundWindow(handle);

        IntPtr hDeskTop = MessageBase.FindWindow(null, "钟大侠文档速度保存");
        MessageBase.SetForegroundWindow(hDeskTop);
    }

    public void KeyDown(byte key)
    {
        MessageBase.keybd_event(key, 0, 0, 0);
    }

    public void KeyUp(byte key)
    {
        MessageBase.keybd_event(key, 0, 2, 0);
    }

    public void KeyClick(byte key)
    {
        MessageBase.keybd_event(key, 0, 0, 0);
        MessageBase.keybd_event(key, 0, 2, 0);
    }
}
